<?

	$jo_copname    = mysql_escape_string(trim($_POST[jo_copname]));
	$jo_copurl     = mysql_escape_string(trim($_POST[jo_copurl]));
	$jo_priname    = mysql_escape_string(trim($_POST[jo_priname]));
	$jo_priemail   = mysql_escape_string(trim($_POST[jo_priemail]));
	$jo_priphone   = mysql_escape_string(trim($_POST[jo_priphone]));
	$jo_copculture = mysql_escape_string(trim($_POST[jo_copculture]));
	$jo_copbenefit = mysql_escape_string(trim($_POST[jo_copbenefit]));
	$jo_type       = mysql_escape_string(trim($_POST[jo_type]));
	$jo_vdate      = mysql_escape_string(trim($_POST[jo_vdate]));
	$jo_status     = mysql_escape_string(trim($_POST[jo_status]));
	$jo_priority   = mysql_escape_string(trim($_POST[jo_priority]));
	$jo_category   = mysql_escape_string(trim($_POST[jo_category]));
	$jo_cat		   = mysql_escape_string(trim($_POST[jo_cat]));
	$jo_function   = mysql_escape_string(trim($_POST[jo_function]));
	$jo_title      = mysql_escape_string(trim($_POST[jo_title]));
	$jo_copreq     = mysql_escape_string(trim($_POST[jo_copreq]));
	$jo_positions  = mysql_escape_string(trim($_POST[jo_positions]));
	$jo_salrange   = mysql_escape_string(trim($_POST[jo_salrange]));
	$jo_bonus	   = mysql_escape_string(trim($_POST[jo_bonus]));
	if($jo_bonus != ''){
	$jo_bonus = date("M d, Y")." --------------\r\n".$jo_bonus; 
	$extraSqlJoBonus = 	" `jo_bonus`='".$jo_bonus."', ";
	}
	$jo_feerange   = mysql_escape_string(trim($_POST[jo_feerange]));
	$jo_address    = mysql_escape_string(trim($_POST[jo_address]));
	$jo_city       = mysql_escape_string(trim($_POST[jo_city]));
	$jo_state      = mysql_escape_string(trim($_POST[jo_state]));
	$jo_country    = mysql_escape_string(trim($_POST[jo_country]));
	$jo_zip        = mysql_escape_string(trim($_POST[jo_zip]));
	$jo_howfar     = mysql_escape_string(trim($_POST[jo_howfar]));
	$jo_jobtravel  = mysql_escape_string(trim($_POST[jo_jobtravel]));
	//$jo_hiringmanager = mysql_escape_string(trim($_POST[jo_hiringmanager]));
	$jo_mer        = mysql_escape_string(trim($_POST[jo_mer]));
	$jo_myrwe      = mysql_escape_string(trim($_POST[jo_myrwe]));
	$jo_ypme       = mysql_escape_string(trim($_POST[jo_ypme]));
	$jo_yplr       = mysql_escape_string(trim($_POST[jo_yplr]));
	$jo_license    = mysql_escape_string(trim($_POST[jo_license]));
	$jo_language   = mysql_escape_string(trim($_POST[jo_language]));
	$jo_authorized = mysql_escape_string(trim($_POST[jo_authorized]));
	$jo_usgsc      = mysql_escape_string(trim($_POST[jo_usgsc]));
	$jo_description= mysql_escape_string(trim($_POST[jo_description]));
	$jo_public     = mysql_escape_string(trim($_POST[jo_public]));
	$jo_private    = mysql_escape_string(trim($_POST[jo_private]));
	$jo_id         = mysql_escape_string(trim($_POST[jo_id]));
	$jo_contact    = !empty($_POST[jo_contact])?@implode(',', $_POST[jo_contact]):'';

    $sql = "UPDATE ".$db_prefix."job
	                 SET 
					 ".$pwd."
					`jo_uid`='".$_SESSION[uid]."'  ,
				    `jo_utype`='".$_SESSION[usertype]."'  ,
				    `jo_username`='".$_SESSION[uname]."'  ,
					`jo_type`='".$jo_type."' ,
					`jo_copname`='".$jo_copname."' ,
					`jo_copculture`= '".$jo_copculture."',
					`jo_copbenefit`='".$jo_copbenefit."',
					`jo_priority`='".$jo_priority."',
					`jo_zip`='".$jo_zip."',
					`jo_copurl`='".$jo_copurl."' , 
					`jo_copreq`='".$jo_copreq."' ,
					`jo_vdate`='".$jo_vdate."',
					`jo_status` ='".$jo_status."' , 
					`jo_category`='".$jo_category."' ,
					`jo_cat`='".$jo_cat."' ,
					`jo_function`='".$jo_function."' , 
					`jo_title`= '".$jo_title."', 
					`jo_positions`='".$jo_positions."' ,
					`jo_salrange`='".$jo_salrange."'  ,
					".$extraSqlJoBonus."
					`jo_address`='".$jo_address."', 
					`jo_city`='".$jo_city."', 
					`jo_feerange`='".$jo_feerange."',
					`jo_state`='".$jo_state."', 
					`jo_country`='".$jo_country."', 
					`jo_license`='".$jo_license."',
					`jo_howfar`='".$jo_howfar."', 
					`jo_mer`='".$jo_mer."', 
					`jo_myrwe`='".$jo_myrwe."', 
					`jo_ypme`='".$jo_ypme."', 
					`jo_yplr`='".$jo_yplr."', 
					`jo_jobtravel`='".$jo_jobtravel."', 
					`jo_language`='".$jo_language."', 
					`jo_authorized`='".$jo_authorized."', 
					`jo_usgsc`='".$jo_usgsc."', 
					`jo_description`='".$jo_description."', 
					`jo_public`='".$jo_public."',
					`jo_private`='".$jo_private."',
					`jo_priname`='".$jo_priname."',
					`jo_priemail`='".$jo_priemail."',
					`jo_priphone`='".$jo_priphone."',
					`jo_secname`='".$jo_secname."',
					`jo_secemail`='".$jo_secemail."',
					`jo_secphone`='".$jo_secphone."',
					`jo_updtime`='".time()."',
					`jo_contact`='".$jo_contact."'
					WHERE jo_id= '".$_POST[id]."' AND jo_uid = '".$_SESSION[uid]."'";
	$DB->query($sql);

	if($jo_status == '2') {
		//Send mail if job status is closed
		require_once("./include/class.phpmailer.php");
		$sql = "SELECT re_fname, re_lname, re_email FROM pa_contact WHERE `re_isapproved` = '1' AND `re_aliasid` = '".$_POST[id]."'";
		$result = $DB->query($sql);
		$emailto = array();

		while($row = $DB->fetch_array($result)){
		   $emailto[$row['re_email']] = $row['re_fname'].' '.$row['re_lname'];
		}

		if(!empty($emailto)){
			foreach($emailto as $email => $username){
				$mail=new PHPMailer();

				$mail->IsMail();
				$mail->From     = $_SESSION['useremail'];
				$mail->FromName = $_SESSION['realname'];
				$mail->AddAddress($email,$username);
				
				$mail->IsHTML(true);
				$mail->Subject = "Closed: ".$jo_title.", ER Job Req#".$_POST[id];
				$mail->Body = "<p>You are receiving this message because the Job Poster has just closed this job, therefore no more candidates will be accepted at this time. To view the status of this job online, simply login to your account at <a href='enetrecruiter.com'>enetRecruiter.com</a> then go to the Approved to Submit section. Please contact the job poster regarding the status of this job.</p> 
				<p><span style='color:gray;'>NOTE: This message was sent to you by a member of enetRecruiter.com. For questions regarding this job, please contact the sender. Any questions regarding your account please contact us at <a href='mailto:account@enetrecruiter.com'>account@enetrecruiter.com</a>. </span></p> 
				";

				$mail->CharSet = 'UTF-8';

				$mail->Send();
			}
		}
	}

    if($_SESSION[usertype]=='recruiter'){
	$err =  "<h3 style=\"color:red\">Your change has been successfully updated!!</h3><meta http-equiv=\"refresh\" content=\"2;URL=myjobs.php\">";
	}else{
	$err =  "<h3 style=\"color:red\">Your change has been successfully updated!!</h3><meta http-equiv=\"refresh\" content=\"2;URL=mypostjobs.php\">";
	}

    $_GET[id] = $_POST[id];
?>